package Master.interfaces;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ArrayList;

import javax.swing.JPanel;
import javax.swing.JScrollPane;

/*
 * Scrollpane template extended froim JScrollPane to provide pre-determined
 * things and functions for adding and displaying visual items within the
 * scrollable panel
 */
public class DisplayScrollPanel extends JScrollPane {
	//Need to organise things neatly
	private JPanel inner_container = new JPanel(new GridBagLayout());
	//Need to align items top
	private JPanel outer_container = new JPanel(new FlowLayout());
	//Items to display
	private ArrayList<PanelItem> items = new ArrayList<PanelItem>(); 
	private int between_space=5;
	
	public DisplayScrollPanel()
	{
		super();
		inner_container.setBackground(Color.WHITE);
		outer_container.setBackground(Color.WHITE);
		this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		this.setHorizontalScrollBarPolicy(
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		
		this.getViewport().add(outer_container);
		outer_container.add(inner_container);
	}
	
	public void add(int grid_x,int grid_y,PanelItem item)
	{
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.HORIZONTAL;
		
		items.add(item);
		c.gridx = grid_x;
		c.gridy = grid_y;
		c.insets = new Insets(between_space, between_space,
								between_space, between_space);
		inner_container.add(item,c);

		this.validate();
		this.repaint();
	}
	
	public void removeAllItems()
	{
		items.clear();
		inner_container.removeAll();
		
		this.validate();
		this.repaint();
	}
}
